#!/usr/bin/python

if __name__ == '__main__':
    import os
    import sys
    from termcolor import colored

def set_color( color_shell_path ):
    if os.path.exists( color_shell_path ):
        rm_command = 'sudo rm -rf /usr/bin/g++'
        re_link_command = 'sudo ln -s %s /usr/bin/g++' %color_shell_path
        exec_command = '%s && %s' %(rm_command, re_link_command)
        print colored( 'begin setting the compiler error color', 'red' )
        if 0==os.system( exec_command ):
            print colored( 'setting the compiler color done', 'red' )
        else:
            print colored( 'setting the compiler color failed', 'red' )
    else:
        print colored( 'color perl shell file is not exist', 'red' )
    ls_command = 'ls -l /usr/bin/g++'
    os.system( ls_command )

def unset_color():
    rm_command = 'sudo rm -rf /usr/bin/g++'
    re_link_command = 'sudo ln -s /usr/bin/g++-4.3 /usr/bin/g++'
    exec_command = '%s && %s' %(rm_command, re_link_command)
    if 0==os.system( exec_command ):
        print colored('unset compiler color done', 'red' )
    else:
        print colored( 'unset compiler color failed', 'red' )
    ls_command = 'ls -l /usr/bin/g++'
    os.system( ls_command )


if __name__ == '__main__':
    argv = sys.argv[1:]
    if 'set' == argv[0]:
        set_color( argv[1] )
    elif 'unset' == argv[0]:
        unset_color()



